package com.yanqu.road.server.cmd.monopolymarket.resgrab;

import com.yanqu.road.entity.enums.eMonopolyMarketResType;
import com.yanqu.road.entity.monopolymarket.resgrab.IMonopolyMarketObjectInfo;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.monopolymarket.MonopolyMarketProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.monopolymarket.MonopolyMarketResGrabMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

/**
 * @Description
 * @Author cwq
 * @Data 2021/8/31 21:55
 */
@Cmd(code = Protocol.C_CROSS_MONOPOLY_MARKET_RES_GRAB_ACTION, desc = "进入资源争夺战 抢夺/撤回位置")
public class CrossMonopolyMarketResGrabActionCmd extends CrossCommand {

    private long userId ;
    private UserBaseInfo userBaseInfo;
    private MonopolyMarketProto.MonopolyMarketResGrabActionReqMsg ctsMsg;
    private List<IMonopolyMarketObjectInfo> objectInfoList;
    // 鼓舞次数
    private int buffAddTimes ;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MonopolyMarketProto.MonopolyMarketResGrabActionCrossReqMsg req = MonopolyMarketProto.MonopolyMarketResGrabActionCrossReqMsg.parseFrom(packet.getBytes());
        userId = packet.getPlayerId();
        ctsMsg = req.getCtsMsg();
        if(req.hasPlayerInfo()){
            userBaseInfo = PlayerBasePb.parseToUserBaseInfo(req.getPlayerInfo());
        }
        if(ctsMsg.getType() == eMonopolyMarketResType.RES_KING.getValue()){
            objectInfoList = MonopolyMarketResGrabMgr.formatPatronsList(req.getPatronsListList());
        }else if(ctsMsg.getType() == eMonopolyMarketResType.RES_QUEEN.getValue()){
            objectInfoList = MonopolyMarketResGrabMgr.formatBeautyList(req.getBeautyListList());
        }
        buffAddTimes = req.getCtsMsg().getBuffAddTimes();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        MessageHelper.sendPacket(serverId, userId , YanQuMessageUtils.buildMessage(GameProtocol.S_MONOPOLY_MARKET_RES_GRAB_ACTION_FROM_CROSS, MonopolyMarketResGrabMgr.action(userId,serverId,ctsMsg,userBaseInfo,objectInfoList,buffAddTimes)));
    }

    @Override
    public void sendData() {

    }
}
